package com.tanguy.user.ui.me.activity

import cn.sinata.xldutils_kotlin.activity.WebViewActivity
import cn.sinata.xldutils_kotlin.utils.SpanBuilder
import com.tanguy.user.Const
import com.tanguy.user.R
import com.tanguy.user.base.ImmersionTitleActivity
import com.tanguy.user.net.http.HttpManager
import com.tanguy.user.utlis.extend.click
import com.tanguy.user.utlis.extend.requestSucceed
import com.tanguy.user.utlis.extend.setText
import org.jetbrains.anko.startActivity

/**
 * Created by dab on 2017/10/10 0010 14:45
 * 推荐有礼
 */
class RecommendActivity : ImmersionTitleActivity() {
    override fun setContentViewRes(): Int = R.layout.activity_recommend
    override fun initView() {
        super.initView()
        title = "推荐有礼"
        click(R.id.tv_rule) { startActivity<WebViewActivity>("url" to Const.AppText.REWARD_RULES, "title" to "奖励规则") }
        HttpManager.getRecommend()
                .requestSucceed(this) {
                    setText(R.id.tv_award, "${it.total}元")
                    setText(R.id.tv_total_money, "已成功邀请${it.num}人，累计获得收益${it.money}元")
                    val content = "您将获得${it.total}元优惠券奖励"
                    val stringBuilder = SpanBuilder(content).color(this@RecommendActivity, 4, content.length - 5, R.color.color_fb408e)
                            .build()

                    setText(R.id.tv_prefer, stringBuilder)
                }

        click(R.id.submit_btn) {
            showToast("推荐好友")
        }
    }
}